//
//  TstGroupchatCell.swift
//  TstChat
//
//  Created by wanghui on 2018/5/10.
//  Copyright © 2018年 daerwei. All rights reserved.
//

import UIKit

class TstGroupchatCell: UITableViewCell {
    
    lazy var headview: UIView = {
        let view = UIView(frame:CGRect(x:0,y:0,width:50,height:50))
        view.backgroundColor = UIColor.clear
        return view
    }()
    //头像
    lazy var headimage: UIImageView = {
        let headImg = UIImageView()
        headImg.layer.cornerRadius = 5
        headImg.layer.masksToBounds = true
        contentView.addSubview(headImg)
        headImg.isUserInteractionEnabled = true
        headImg.backgroundColor = UIColor.clear
        headImg.backgroundColor = UIColor.gray
        return headImg
    }()
    
    //名称
    lazy var nameLabel: UILabel = {
        let nlabel = UILabel()
        nlabel.font = UIFont.systemFont(ofSize: 15.0)
        nlabel.textAlignment = .left
        nlabel.numberOfLines = 1
        nlabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
        contentView.addSubview(nlabel)
        return nlabel
    }()
    
    //最新的消息
    lazy var lastestnews: UILabel = {
        let nlabel = UILabel()
        nlabel.textColor = UIColor.lightGray
        nlabel.font = UIFont.systemFont(ofSize: 13.0)
        nlabel.textAlignment = .left
        nlabel.numberOfLines = 1
        contentView.addSubview(nlabel)
        return nlabel
    }()
    
    //最新消息的发送时间
    lazy var latestTime: UILabel = {
        let nlabel = UILabel()
        nlabel.font = UIFont.systemFont(ofSize: 12.0)
        nlabel.textAlignment = .right
        nlabel.textColor = UIColor.lightGray
        nlabel.setContentCompressionResistancePriority(UILayoutPriority.required, for: .horizontal)
        contentView.addSubview(nlabel)
        return nlabel
    }()
    
    //消息免打扰标志
    lazy var nodisturbImage: UIImageView = {
        let imageview = UIImageView.init()
        contentView.addSubview(imageview)
        imageview.backgroundColor = UIColor.clear
        imageview.image = UIImage(named: "nodisturbing")
        imageview.isHidden = true
        return imageview
    }()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        //添加子view
        self.contentView.addSubview(headimage)
        self.contentView.addSubview(headview)
        self.contentView.addSubview(nameLabel)
        self.contentView.addSubview(lastestnews)
        self.contentView.addSubview(nodisturbImage)
        self.backgroundColor = .systemBackground
        self.separatorInset = UIEdgeInsets(top: 0, left: 70, bottom: 0, right: 0)
        
        headimage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.width.height.equalTo(50)
        }
        
        headview.snp.makeConstraints { (make) in
            make.edges.equalTo(headimage)
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(headview.snp.top).offset(5)
            make.left.equalTo(headview.snp.right).offset(10)
            make.right.equalTo(latestTime.snp.left).offset(5)
            make.height.equalTo(20)
        }
        
        lastestnews.snp.makeConstraints { (make) in
            make.left.equalTo(nameLabel.snp.left).offset(0)
            make.bottom.equalTo(headview.snp.bottom).offset(-5)
        }
        
        latestTime.snp.makeConstraints { (make) in
            make.top.equalTo(nameLabel.snp.top).offset(0)
            make.right.equalToSuperview().offset(-10)
        }
        
        nodisturbImage.snp.makeConstraints { (make) in
            make.right.equalTo(latestTime.snp.right).offset(0)
            make.bottom.equalTo(lastestnews.snp.bottom).offset(0)
            make.left.equalTo(lastestnews.snp.right).offset(5)
            make.width.equalTo(13)
            make.height.equalTo(13)
        }
        self.selectionStyle = .gray
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
